Skip to content

fix: add error handling for launchUrl in About Us feedback link#3382

Merged
marcnause merged 3 commits into
fossasia:mainfrom
prajakta128:fix/about-us-launchurl-crash-clean
Jul 1, 2026
Merged

fix: add error handling for launchUrl in About Us feedback link#3382
marcnause merged 3 commits into
fossasia:mainfrom
prajakta128:fix/about-us-launchurl-crash-clean

Conversation

@prajakta128

@prajakta128 prajakta128 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #3374

Problem

The feedback/bug-report link in the About Us screen called launchUrl() directly with no canLaunchUrl check and no try/catch. If the URL fails to launch for any reason (no browser, network issue, invalid URL), the app throws an unhandled exception and crashes.

Root Cause

Line 138 of lib/view/about_us_screen.dart called launchUrl directly without checking if the URL could actually be launched. Other links in the same file already use a canLaunchUrl guard correctly, but this one was missed.

Fix

Added a canLaunchUrl check before calling launchUrl, consistent with the existing pattern used by other links in the same file. If the URL cannot be launched, it now logs a debug message instead of crashing.

Impact

  • Prevents app crash when feedback URL cannot be launched
  • Consistent with how all other links in about_us_screen.dart are handled
  • No UI change

Screenshots / Recordings

N/A — crash fix, no UI changes

Checklist

  • No hard coding: I have used values from constants.dart or localization files instead of hard-coded values.
  • No end of file edits: No modifications done at end of resource files.
  • Code reformatting: I have formatted the code using dart format or the IDE formatter.
  • Code analysis: My code passes checks run in flutter analyze and tests run in flutter test.

Summary by Sourcery

Add defensive URL launch handling for the About Us feedback link to prevent crashes when the feedback form cannot be opened.

Bug Fixes:

  • Prevent app crashes on the About Us feedback link by checking URL launch capability before invoking launchUrl.

Enhancements:

  • Improve error logging formatting when version information fails to load.

@sourcery-ai

sourcery-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds proper error handling around the About Us feedback URL tap handler by guarding launchUrl with canLaunchUrl and logging failures, and performs a small formatting cleanup in version-info error logging.

Sequence diagram for updated About Us feedback link error handling

sequenceDiagram
    actor User
    participant AboutUsScreen
    participant UrlLauncher
    participant Logger

    User ->> AboutUsScreen: onTap
    AboutUsScreen ->> UrlLauncher: canLaunchUrl(uri)
    UrlLauncher -->> AboutUsScreen: bool

    alt [canLaunchUrl is true]
        AboutUsScreen ->> UrlLauncher: launchUrl(uri)
    else [canLaunchUrl is false]
        AboutUsScreen ->> Logger: debugPrint
    end
Loading

File-Level Changes

Change Details Files
Add error handling around launching the feedback form URL to prevent crashes when the URL cannot be opened.
  • Parse the feedbackForm string into a Uri before use.
  • Check canLaunchUrl(uri) before calling launchUrl(uri).
  • Log a debugPrint message when the URL cannot be launched instead of throwing an exception.
lib/view/about_us_screen.dart
Minor formatting adjustment to version information error logging for consistency/readability.
  • Reformat the logger.e call string interpolation to comply with style/formatter expectations.
lib/view/about_us_screen.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#3374 Add error handling for the About Us feedback/bug-report link so that launchUrl failures do not crash the app.
#3374 Ensure the feedback/bug-report link in about_us_screen.dart follows the same canLaunchUrl-guarded pattern as other links in the file.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • Instead of using debugPrint for the failure case, consider routing this through the existing logger to keep logging behavior consistent with the rest of the screen.
  • Right now a failure to open the feedback URL is only logged; consider providing a small user-visible indication (e.g., a Snackbar) so users understand why nothing happened when they tapped the link.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Instead of using `debugPrint` for the failure case, consider routing this through the existing `logger` to keep logging behavior consistent with the rest of the screen.
- Right now a failure to open the feedback URL is only logged; consider providing a small user-visible indication (e.g., a Snackbar) so users understand why nothing happened when they tapped the link.

## Individual Comments

### Comment 1
<location path="lib/view/about_us_screen.dart" line_range="138" />
<code_context>
                 ),
                 onTap: () async {
-                  await launchUrl(Uri.parse(appLocalizations.feedbackForm));
+                  final uri = Uri.parse(appLocalizations.feedbackForm);
+                  if (await canLaunchUrl(uri)) {
+                    await launchUrl(uri);
</code_context>
<issue_to_address>
**suggestion:** Consider using the existing logger and/or surfacing a user-visible error instead of debugPrint.

`debugPrint` limits visibility of failures to debug builds only. Since this is user-facing and you’re already using `logger` in this file, please log via `logger` instead and consider lightweight UI feedback (e.g. a snackbar) so users are aware when opening the feedback form fails.

Suggested implementation:

```
                  final uri = Uri.parse(appLocalizations.feedbackForm);
                  if (await canLaunchUrl(uri)) {
                    await launchUrl(uri);
                  } else {
                    logger.e(
                      'Could not launch feedback form URL',
                      'url=${appLocalizations.feedbackForm}',
                    );
                    ScaffoldMessenger.of(context).showSnackBar(
                      SnackBar(
                        content: Text(
                          appLocalizations.feedbackFormOpenError,
                        ),
                      ),
                    );
                  }

```

1. Ensure `appLocalizations.feedbackFormOpenError` (or equivalent) exists; if not, add a localized string for the snackbar message.
2. If your project uses a custom snackbar helper instead of `ScaffoldMessenger.of`, replace that call with the appropriate helper while keeping the `logger.e` call.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread lib/view/about_us_screen.dart
The feedback/bug-report link in about_us_screen.dart called launchUrl()
directly with no canLaunchUrl check and no try/catch. If the URL fails
to launch for any reason, the app throws an unhandled exception and
crashes.

Added canLaunchUrl check before calling launchUrl, consistent with the
existing pattern used by other links in the same file.

Fixes fossasia#3374
Per code review feedback, replaced debugPrint with the project's
existing logger service to keep logging consistent with the rest
of the app.
The buildContactList onTap was accidentally pointing to the feedback
form URL instead of each contact item's own URL. Also fixed logger.e
calls to use a single string argument, matching the pattern used
elsewhere in the file, and restored the original version-error message.
@marcnause marcnause force-pushed the fix/about-us-launchurl-crash-clean branch from e6af0fc to 2ec43dc Compare July 1, 2026 20:29
@marcnause marcnause enabled auto-merge (squash) July 1, 2026 20:32
@marcnause marcnause merged commit 43d7eb6 into fossasia:main Jul 1, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: launchUrl in About Us screen crashes app when URL cannot be launched

2 participants